[#ftl]
[@define "agile.grid.GridHeader" "agile._Component,agile._Resizable"]
	 widgetName:"GridHeader"	
	 [#assign templateString]
	 <div class="agileComponent agileDataGridColumn">
	 	<div data-dojo-attach-point="header" data-dojo-type="dijit/InlineEditBox" width="{parameters.width}" style="width:{parameters.width};height:20px">{parameters.header}</div>
	 	[#--<img data-dojo-attach-point="removeButton" class='agileButton agileButtonRemove agileGridHeaderRemoveButton'/>--]
	 </div>
	 [/#assign]
	 ,templateString: "${templateString?js_string}"
	 ,templateMap:{
	 	dojo:"<th {html-parameters}>{innerWidets}</th>\n"
	 	,agile:"<th {html-parameters}>{innerWidets}</th>\n"
	 }		
	 ,resizeAxis:"x"	
	 ,styleConstraints:agile.delegate(agile._Component.prototype.styleConstraints,{
			"position":{_ignore:false}
			,"left":{_ignore:false,_readOnly:true}
			,"top":{_ignore:true,_readOnly:true}
			,"width":{_ignore:true,_readOnly:true}
			,"height":{_ignore:true,_readOnly:true}
		})
    ,attributes:agile.delegate(agile._Component.prototype.attributes,{
	 	field:lang.mixin({},agile.TextMetadata,{			
	 		_readOnly:true,_hidden:true,label:"i18n_field"
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);					
	 		}				
	 	})
	 	,header:lang.mixin({},agile.TextMetadata,{
	 		label:"i18n_header"
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 			widget.header.reset1("value",value);
	 		}
	 		,ignore:function(widget,sourceType){
	 			return true;
	 		}
	 	})
	 	,width:lang.mixin({},agile.NumberMetadata,{	
	 		unit:"px",label:"i18n_width",positive:true
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 			style.set(widget.domNode,name,value);
	 			widget.metadata("style."+name,value);
	 			widget.parent.adjustColumnWidth(widget);
	 		}
	 	})
	 	,editable:lang.mixin({},agile.BooleanMetadata,{	
	 		label:"i18n_editable"
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 		}
	 		,ignore:function(widget,sourceType){
	 			return !widget.metadata("parameters.editable");
	 		}
	 	})
	 	,cellType:lang.mixin({},agile.ComboMetadata,{
	 		label:"i18n_cell_type"
	 		,options:[{value:""},{value:"dojox.grid.cells.Bool"},{value:"dojox.grid.cells.Select"}]
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 		}
	 		,readOnly:function(widget,sourceType){
	 			return !widget.metadata("parameters.editable");
	 		}
	 		,ignore:function(widget,sourceType){
	 			return !widget.metadata("parameters.editable");
	 		}
	 	})
	// ,draggable:lang.mixin({},agile.BooleanMetadata,{
	// onValueChange:function(widget,name,value){
	// widget.metadata("parameters."+name,value);
	// }
	// ,ignore:function(widget,sourceType){
	// return !widget.metadata("draggable");
	// }
	// })
	 	,hidden:lang.mixin({},agile.BooleanMetadata,{	
	 		label:"i18n_hidden"
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 			widget.parent.hideColumn(widget);
	 		}
	 		,ignore:function(widget,sourceType){
	 			return !widget.metadata("parameters.hidden");
	 		}
	 	})
// ,_hidden:lang.mixin({},agile.BooleanMetadata,{_hidden:true
// ,ignore:function(widget,sourceType){
// return sourceType == "dojo";
// }
// })
	 	,sortInfo:lang.mixin({},agile.TextMetadata,{			
	 		onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 		}
	 	})
	 	,formatter:lang.mixin({},agile.FunctionEditor,{
	 		_hidden:true,args:"value"
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 		}
	 	})
	 	,get:lang.mixin({},agile.FunctionEditor,{
	 		_hidden:true,args:"rowIndex,item"
	 		,onValueChange:function(widget,name,value){	
	 			widget.metadata("parameters."+name,value);
	 		}
	 	})
	 	,wid:{_ignore:true}
	 })
	 ,initDefaultMetadata:function(){
		 	this.metadata("parameters.header","");
		 	this.metadata("parameters.field","field"+(new Date().getTime()));
		 	this.metadata("style.width","100px");
		 	this.metadata("parameters.width","100px");
		 	this.metadata("parameters.editable",true);
		 	this.metadata("parameters.hidden",false);
//		 	this.metadata("moveable",true);		
	 }
	 ,constructor:function(){
	 		
	 	// this.metadata("constrainedMoveable",true);
	 }
	 ,init:function(){

		 this.metadata("style.width",this.metadata("parameters.width"));
		 if(this.metadata("parameters.hidden")){
			 style.set(this.domNode,"visibility","hidden");
			 // style.set(this.domNode,"display","none");
		 }else{
		 		this.resetInlineEditBox(this.header);	
		 		
		 		this.header.watch("value",lang.hitch(this,function(name,oldValue,newValue){
		 			topic.publish("agile.widget.changed",this.category,"header",newValue);					
		 			this.metadata("parameters.header",newValue);				
		 		}));
		 		
		 		this.own(			 		
			 		on(this.header,"edit",lang.hitch(this,function(){
			 			var editWidget = this.header.wrapperWidget.editWidget;
			 			style.set(editWidget.domNode,{width:this.metadata("parameters.width")});
			 		}))
			 		,on(this.header,"focus",lang.hitch(this,function(){
			 			topic.publish("agile.widget.selected",this);
			 			this.onSelected();
			 		}))
//			 		,on(this.domNode,"mouseover",lang.hitch(this,function(){
//			 			if(this.parent.getChildren().length > 1){
//			 				style.set(this.removeButton,"display","inline");
//			 			}
//			 			// style.set(this.addButton,"display","inline");
//			 		}))
//			 		,on(this.domNode,"mouseout",lang.hitch(this,function(){
//			 			style.set(this.removeButton,"display","none");
//			 		}))
//			 		,on(this.removeButton,"click",lang.hitch(this,function(event){
//			 			this.parent.removeColumn(this);
//			 		}))
		 		);
		 		
//		 		this.removeButton.title = agile.i18n("remove_btn_tooltip",["column"],true);
		 }
		 
		 on(this.domNode,mouse.enter,lang.hitch(this,function(evt){								
			this.parent.showControlButtons(this,evt);
		}));
	 }
	 ,getResizableTargetContainer:function(){							
	 	return this.domNode;		 
	 }
 	,onResizeStop:function(marginBox){
// //console.log(this.declaredClass,"agile._Resizable:onResizeStop",marginBox);
		topic.publish("agile.widget.changed.styles",this,"style.width",marginBox.w+"px");					
		this.metadata("style.width",(marginBox.w + this.getContainerOutterBox().w)+"px");			

		this.metadata("parameters.width",this.metadata("style.width"));
 		topic.publish("agile.widget.changed",this.category,"width",this.metadata("style.width"));
// 		style.set(this.domNode,"width",this.metadata("style.width"));
 		this.parent.adjustColumnWidth(this); 		
	}
	 ,onMoveStop:function(offset){
	 	this.parent.moveColumn(this);
	 }
	 ,toHtml:function(params){
		 params.cascade = true;
		 return this.inherited(arguments);
	 }
	,getInnerWidgetTemplate:function(params){
		return this.metadata("parameters.header");
	}
	,getToolbarAnchorNode:function(){
		return this.domNode;
	}
 [/@]

